package cn.gengar.infrastructure.dcc;


import cn.gengar.types.annotations.DCCValue;
import org.springframework.stereotype.Service;

@Service
public class DCCService {

    // 0 - 默认为不拦截
    // 1 - 拦截
    @DCCValue("downgradeSwitch:0")
    private String downgradeSwitch;


    // 0 - 100 (流量范围)
    @DCCValue("cutRange:100")
    private String cutRange;


    public boolean isDowngradeSwitch() {
        return "1".equals(downgradeSwitch);
    }

    public boolean isCutRange(String userId) {
        int hashCode = Math.abs(userId.hashCode());
        // 后两位
        int lastTwoDigits = hashCode % 100;

        return lastTwoDigits <= Integer.parseInt(cutRange);
    }
}
